local Command = require "command"
local lume = require (LIB_PATH.."lume")

return Command("echo", {

		  {	"%", function (table_name, ...)
			   if not table_name then return end
			   local tbl = _G[table_name]
			   if not tbl then return table_name .. " not found" end
			   if type(tbl) ~= 'table' then return tbl end
			   if not ... then
			      local keys = lume.keys(tbl)
			      local fmt = string.rep("%s ", #keys)
			      return string.format(fmt, unpack(keys))
			   end
			   local t = {...}
			   local val
			   if not lume.any(t, function (v)
					      val = v
					      return tbl[v]
			   end) then return val.." isn't in " ..table_name end
			   
			   return lume.reduce(lume.map(t, function (v)
							  local m
							  if type(v) == "table" then
							     m = pl.pretty.write()
							  else
							     m = tbl[v]
							  end
							  return m
						      end),
					      function (v1, v2)
						 return string.format("%s %s", v1, v2)
			   end)
		  end,
		  },

})
